package com.hfkh.keyun.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ApiResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer code;
    private String message;
    private T data;

    public static <T> ApiResult<T> success(T data) {
        return ApiResult.success(StatusCodeEnum.SC200.getMessage(), data);
    }

    public static <T> ApiResult<T> success(String msg, T data) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(StatusCodeEnum.SC200.getCode());
        apiResult.setMessage(msg);
        apiResult.setData(data);
        return apiResult;
    }

    public static <T> ApiResult<T> success(Integer code,String message, T data) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(code);
        apiResult.setMessage(message);
        apiResult.setData(data);
        return apiResult;
    }

    public static <T> ApiResult<T> success(StatusCodeEnum sce, T data) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(sce.getCode());
        apiResult.setMessage(sce.getMessage());
        apiResult.setData(data);
        return apiResult;
    }

    public static <T> ApiResult<T> fail() {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(StatusCodeEnum.SC999.getCode());
        apiResult.setMessage(StatusCodeEnum.SC999.getMessage());
        return apiResult;
    }
    public static <T> ApiResult<T> ok(String msg, String s) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(0);
        apiResult.setMessage(msg);
        return apiResult;
    }
    public static <T> ApiResult<T> fail(String msg) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(1);
        apiResult.setMessage(msg);
        return apiResult;
    }

    public static <T> ApiResult<T> fail(Integer code,String msg) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(code);
        apiResult.setMessage(msg);
        return apiResult;
    }

    public static <T> ApiResult<T> fail(StatusCodeEnum sce, String msg) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(sce.getCode());
        apiResult.setMessage(sce.getMessage());
        return apiResult;
    }


    public static <T> ApiResult<T> error(){
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(StatusCodeEnum.SC500.getCode());
        apiResult.setMessage(StatusCodeEnum.SC500.getMessage());
        return apiResult;
    }

}
